﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CommerceOne.Domains.Commons
{
    public class PriceParam<T> : IFilterParam
    {
        private List<T> paramList = new List<T>();

        public string FieldName { get; set; }

        public string ObjectName { get; set; }

        public FilterType Type { get; set; }

        public void AddValue(object value)
        {
            T t = (T) value;
            this.paramList.Add(t);
        }

        public override string ToString()
        {
            if (this.paramList.Count == 0) return string.Empty;
            string str = string.Empty;
            if (this.paramList.Count == 1) str = string.Format("(( {0}.EnablePrice2 = '1' AND {0}.Price2 >= {1}) OR ( {0}.EnablePrice2 = '0' AND {0}.Price1 >= {1}))", this.FieldName, this.paramList[0]);
            if (this.paramList.Count == 2) str = string.Format("(( {0}.EnablePrice2 = '1' AND {0}.Price2 >= {1} AND {0}.Price2 < {2}) OR ( {0}.EnablePrice2 = '0' AND {0}.Price1 >= {1} AND {0}.Price1 < {2}))", this.FieldName, this.paramList[0], this.paramList[1]);
            return str;
        }
    }
}
